package com.ryzx.log.collector;

/*
请求耗时类，用于对请求处理耗时进行耗时级别定义
 */
public enum TimeCostEnum {
    M1(0, 20, "M1"),
    M2(20, 40, "M2"),
    M3(40, 60, "M3"),
    M4(60, 80, "M4"),
    M5(80, 100, "M5"),
    M6(100, 150, "M6"),
    M7(150, 200, "M7"),
    M8(200, 300, "M8"),
    M9(300, 999999999, "M9"),
    ;
    private final int beginValue;
    private final int endValue;
    private final String costMark;
    TimeCostEnum(int beginValue, int endValue, String costMark) {
        this.beginValue = beginValue;
        this.endValue = endValue;
        this.costMark = costMark;
    }
    public int getBeginValue() {
        return beginValue;
    }
    public int getEndValue() {
        return endValue;
    }
    private String getCostMark() {
        return costMark;
    }
    public static String costMark(long costTime) {
        String mark = "M0";
        for (TimeCostEnum timeCostEnum : TimeCostEnum.values()) {
            long beginValue = timeCostEnum.getBeginValue();
            long endValue = timeCostEnum.getEndValue();
            if (beginValue < costTime && costTime <= endValue) {
                mark = timeCostEnum.getCostMark();
                break;
            }
        }
        return mark;
    }
}